<style>
#TimerMenuTable{
	margin: 4px 0px;
}
#TimerPathText{
	margin-right: 8px;
}
#QueryTimerButton{
	margin-left: 9px;
}
#UptimeLabel{
	color: #345;
	margin-top: 32px;
	margin-left: 8px;
}
</style>

<div>
	<table id='TimerMenuTable'>
		<tr>
			<td>
				<v-text id='TimerPathText' title='任务路径'></v-text>
				<v-select id='TimerStatusSelect' title='执行状态' option='|执行失败|等待执行|执行成功'></v-select>
				<v-button id='QueryTimerButton' title='查询'></v-button>
			</td>
		</tr>
	</table>
	<div id='TimerListDiv'></div>
	<div id='UptimeLabel'></div>
</div>

<script>
getVue('TimerMenuTable');

var vmdata = {
	title: {
		path: '任务路径',
		timeval: '任务类型',
		status: centerText('执行状态', 'bold'),
		statetime: centerText('执行时间', 'bold')
	},
	check: function(data){
		$('#UptimeLabel').text('更新时间：' + data.datetime);
	},
	filter: {
		timeval: function(val){
			if (val.indexOf(':') > 0) return '每天<red>' + val + '</red>执行';
			return '每隔<red>' + val + '秒钟</red>执行一次'
		},
		status: function(val){
			if (val > 0) return centerText('<green>执行成功</green>');
			if (val < 0) return centerText('<red>执行失败</red>');
			return centerText('<blue>等待执行</blue>');
		},
		statetime: centerText
	},
	button: [{
			title: '强制执行',
			click: execTimerTask
		}
	]
};

var listview = new RecordListView('TimerListDiv', '/GetTimerList', vmdata, function(){
	return {path: $('#TimerPathText').val(), status: $('#TimerStatusSelect').val()};
});

$('#TimerPathText').keyup(function(){
	$(this).val($(this).val().toLowerCase());
	listview.reload(false);
});

$('#TimerStatusSelect').change(function(){
	listview.reload(false);
});

$('#QueryTimerButton').click(function(){
	listview.reload(true);
});

function execTimerTask(item){
	var path = item.path;

	showConfirmMessage('执行定时任务[' + path + ']确认？', '执行选项', function(flag){
		if (flag){
			getHttpResult('/ExecModule', {cmd: 'call', async: 1, path: path}, function(data){
				if (data.code == XG_TIMEOUT){
					sessionTimeout();
				}
				else if (data.code < 0){
					showToast('执行定时任务失败');
				}
				else{
					showToast('执行定时任务成功');
				}
			});
		}
	});
}

setSingletonInterval('timerlist_timer', 3000, listview.reload);
</script>